<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>写博客页面</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/themes/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/controls/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/controls/ueditor/ueditor.all.min.js"></script>
<!-- 建议手动加载语言，避免在IE下有时因为加载语言失败导致编辑器加载失败 -->
<!-- 这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目配置的英文，这里加载的中文，那最后就是中文 -->

<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/controls/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
	function submitData() {
		var title = $("#title").val();
		var blogTypeId = $("#blogTypeId").combobox("getValue");
		var content = UE.getEditor('editor').getContent();
		var keyword = $("#keyword").val();
		
		if(title == null | title == "") {
			$.messager.alert("系统提示", "请输入标题!");
		} else if(blogTypeId == null || blogTypeId == "") {
			$.messager.alert("系统提示", "请选择博客类别!");
		} else if(content == null || content == "") {
			$.messager.alert("系统提示", "请输入博客内容!");
		} else {
			$.post("${pageContext.request.contextPath}/admin/blog/save.do", {
				'title' : title,
				'blogType.blogTypeId' : blogTypeId,
				'content' : content,
				'contentNoTag' : UE.getEditor('editor').getContentTxt(),
				'summary' : UE.getEditor('editor').getContentTxt().substr(0, 155),
				'keyword' : keyword
			}, function(result) {
				if(result.success) {
					$.messager.alert("系统提示", "博客发布成功!");
					resetValue();
				} else {
					$.messager.alert("系统提示", "博客发布失败!");
				}
			}, "json");
		}
	}	

	function resetValue() {
		$("#title").val("");
		$("#blogTypeId").combobox("setValue", "");
		UE.getEditor('editor').setContent("");
		$("#keyword").val("");
	}
</script>
</head>
<body style="margin: 10px">
	<div id="p" class="easyui-panel" title="写博客" style="padding: 10px">
		<table cellspacing="20px">
			<tr>
				<td style="width: 80px">博客标题:</td>
				<td>
					<input type="text" id="title" name="title" style="width: 400px" />
				</td>
			</tr>
			<tr>
				<td>所属类别:</td>
				<td>
					<select id="blogTypeId" class="easyui-combobox" name="blogType.blogTypeId" editable="false" panelHeight="auto" style="width: 154px;" >
						<option value="">请选择博客类别</option>
						<c:forEach items="${blogTypeList}" var="blogType">
							<option value="${blogType.blogTypeId}">${blogType.typeName}</option>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td style="vertical-align: top;">博客内容:</td>
				<td>
					<script type="text/plain" id="editor" style="width: 900px; height: 400px;"></script>
				</td>
			</tr>
			<tr>
				<td>关键字:</td>
				<td>
					<input type="text" id="keyword" name="keyword" style="width: 400px;" />&nbsp;&nbsp;&nbsp;(多个关键字请用空格隔开)
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<a href="javascript:submitData()" class="easyui-linkbutton" data-options="iconCls:'icon-submit'">发布博客</a>
				</td>
			</tr>
		</table>
	</div>
	
	<script type="text/javascript">
		var ue = UE.getEditor('editor');
	</script>
</body>
</html>